﻿/*
 * ©2012 XELF
 * http://xelf.info
 */

using Microsoft.Xna.Framework;

namespace XELF.Framework {
	public partial struct DualQuaternion {
		/// <summary>
		/// 剛体変換（ワールド）行列から作る。
		/// </summary>
		public static void CreateFromMatrix(ref Matrix value, out DualQuaternion result) {
			Quaternion rotation;
			Quaternion.CreateFromRotationMatrix(ref value, out rotation);
			Vector3 position = value.Translation;
			DualQuaternion.CreateFromRotationPosition(ref rotation, ref position, out result);
		}

		/// <summary>
		/// 剛体変換（ワールド）行列から作る。
		/// </summary>
		public static DualQuaternion CreateFromMatrix(Matrix value) {
			DualQuaternion result;
			CreateFromMatrix(ref value, out result);
			return result;
		}
	}

	public partial struct DualQuaternion {
		/// <summary>
		/// 位置、前方、上方から作る。
		/// </summary>
		public static void CreateWorld(ref Vector3 position, ref Vector3 forward, ref Vector3 up,
			out DualQuaternion result) {
			Matrix matrix;
			Matrix.CreateWorld(ref position, ref forward, ref up, out matrix);
			CreateFromMatrix(ref matrix, out result);
		}

		/// <summary>
		/// 位置、前方、上方から作る。
		/// </summary>
		public static DualQuaternion CreateWorld(Vector3 position, Vector3 forward, Vector3 up) {
			DualQuaternion result;
			CreateWorld(ref position, ref forward, ref up, out result);
			return result;
		}
	}
}
